package org.tinygroup.channel.protocol.impl;

import org.tinygroup.channel.protocol.ProtocolProcess;
import org.tinygroup.context.Context;

public class BaseProtocolIn<RequestMsg, ResponseMsg> extends
		AbstractProtocolInInterface<RequestMsg, ResponseMsg> {
	private ProtocolProcess protocolProcess;

	public void setProtocolProcess(ProtocolProcess protocolProcess) {
		this.protocolProcess = protocolProcess;
	}

	public ProtocolProcess getProtocolProcess() {
		return protocolProcess;
	}

	protected ResponseMsg realDeal(RequestMsg requestMsg, Context context) {
		Object param = getProtocolTrans().transReqFromMessage(requestMsg, context);
		Object result = getProtocolProcess().process(param, context);
		return (ResponseMsg) getProtocolTrans().transRespToMessage(result, context);
	}

}
